<template>
  <div class="tag-item">
    <span>{{item.tagTitle}}</span>
    <div class="tag-list" >
      <span v-for="tag in item.tagList" :key="tag" @click.stop="giveClass">{{tag}}</span>
    </div>
  </div>
</template>

<script>
export default {
    name:'tagItem',
    props:{
        item:{
            type:Object
        }
    },
    data(){
      return {
        dom:1
      }
    },
    methods:{
      // 增删类名,改变样式
      giveClass(e){
        e.target.classList.toggle("tag-item-active");
        if(this.dom!=1){
          this.dom.classList.remove("tag-item-active")
        }
        this.dom=e.target;
      }
    }
}
</script>

<style>
.tag-item{
  display: flex;
    position: relative;
    width: 100%;
    margin-bottom: 15px;
}
.tag-item>span{
    float: left;
    display: block;
    width: 71px;
    margin-top: 12px;
    height: 29px;
    font-size: 14px;
    text-align: left;
}
.tag-item .tag-list{
  display: flex;
  flex: 1;
}
.tag-item .tag-list>span{
  cursor: pointer;
    display: block;
    float: left;
    padding: 5px 15px;
    margin: 7px 15px;
    text-align: center;
    font-size: 14px;
    transition: all .5s ease;
    border-radius: 12px;
}
.tag-item .tag-list>span:hover,.tag-item-active{
  background-color: #8c30f5;
  color: #fff
}
</style>